<?php 
  
  /**
   * 
   DROP TABLE IF EXISTS `dict_message`;
  CREATE TABLE `dict_message` (
  `m_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` int(10) unsigned NOT NULL COMMENT '消息类型，与dict_message_type形成外键关联',
  `content` varchar(255) DEFAULT '这是一个空消息',
  `status` tinyint(2) NOT NULL,
  `url` varchar(50) DEFAULT '#',
  `u_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`m_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
   */
  Class CommentModel extends RelationModel{
    protected $_link = array(
        'MessageType' => array(
          'mapping_type'  => BELONGS_TO,
          'class_name'    => 'MessageType',
          'foreignkey'    => 'type',
          // 'mapping_name'  => 'messagetype',
          'mapping_fields'=> 'name',
          'as_field'      => 'type'
          ),
      );

    /**
     * 获得一个人的所有消息
     * @param  [type] $u_id [description]
     * @return [type]       [description]
     */
    public function selectMessageByUid($u_id, $status = 0)
    {
      return $this->where('u_id=' . $u_id . ' and status=' . $status)->select();
    }

    /**
     * 添加一个message
     * @param [type] $data [description]
     */
    public function addMessage($data)
    {
      $data['status'] = 0;
      return $this->add($data);
    }

    /**
     * 根据id删除某一条评论，只有拥有者有权限删除这一条评论
     * @param  int    $m_id [description]
     * @param  int    $u_id [description]
     * @return [type]       [description]
     */
    public function delMessageByMid(int $m_id, int $u_id)
    {
      return $this->where('m_id=' . $m_id . " and u_id=" . $u_id)->delete();
    }
  }
 ?>